Method, device and terminal for generating training data

ABSTRACT

A method, a device and a terminal for generating training data is provided. The method for generating training data includes: obtaining an original image; determining a transferred image based on the image style transfer model and the original image, wherein the image style transfer model is obtained by minimizing a loss function, the loss function is determined by the original loss function the background loss function and the foreground loss function; determining the training data based on the transferred image. The difference between the generated training data and the target image is small, thereby improving the accuracy of the training model obtained by using the training data.

CROSS-REFERENCE TO RELATED APPLICATION

This application claims the priority benefit of Chinese PatentApplication No. 201910088005.7 filed on Jan. 29, 2019, the entirecontents of which are hereby incorporated by reference.

FIELD OF TECHNOLOGY

The following relates to the field of image processing, and inparticular, to a method, a device and a terminal for generating trainingdata.

BACKGROUND

With the development of artificial intelligence technology, intelligentcontainer systems capable of automatically identifying goods haveemerged. The intelligent container system captures images of goods inits container through one or more cameras provided in the container, andtransmits the captured images of the goods to a server end. Theidentification algorithm of the server end identifies and calculates thetypes and quantities of the goods in the container in real time.

The automatic identification of goods is realized by visualidentification technology based on deep learning. The accurateidentification based on deep learning technology requires a large amountof training data sets to be included for support, wherein the more thedata for training is contained in the training data set, the moreaccurate the training results would be. At present, the data sets forgoods identification are usually obtained by taking photos manually, forexample, by taking pictures including the container and the items, aftermanually adjusting the position and angle of items on the container. Dueto the large variety and the unlimited number of items, the angles forpositioning items and the occlusion among items, it is very difficult tomanually collect sample images, and the amount of sample data collectedis limited. In order to solve the problem of insufficient sample data inthe training data set, data synthetization is adopted for obtaining thesample data, that is, the sample data is generated by machine.

The inventor found that at least the following problems exist inconventional art: while forming the training data set by synthesizedsample data greatly increases the number of sample data in the trainingdata set, the synthesized sample data is often quite different from thesample data collected in real, thus a model trained with the synthesizedsample data is inaccurate, thereby reducing the item identificationcapability.

SUMMARY

An aspect relates to a method, a device and a terminal for generatingtraining data and a terminal, enabling a small difference between thegenerated training data and a target image, thus enhancing accuracy ofthe training model obtained with the training data.

To solve the above technical problem, an embodiment of the presentdisclosure provides a method for generating training data, including:obtaining an original image; determining a transferred image accordingto an image style transfer model and the original image, the image styletransfer model being obtained by minimizing a loss function, the lossfunction being determined according to an original loss function, abackground loss function, and a foreground loss function; anddetermining the training data according to the transferred image;wherein, the original loss function is configured to indicate a degreeof difference between the transferred image and a target image, and thebackground loss function is configured to indicate a degree ofdifference between a background image in the transferred image and abackground image in the target image, the foreground loss function isconfigured to indicate a degree of difference between a foreground imagein the transferred image and a foreground image in the target image.

An embodiment of the present disclosure further provides a device forgenerating training data, including: an obtaining module, a firstdetermining module, and a second determining module; wherein theobtaining module is configured to obtain an original image; the firstdetermining module is configured to determine a transferred imageaccording to an image style transfer model and an original image, theimage style transfer model is obtained by minimizing a loss function,and the loss function is determined according to an original lossfunction, a background loss function, and a foreground loss function;the second determining module is configured to determine the trainingdata according to the transferred image; wherein, the original lossfunction is configured to indicate a degree of difference between thetransferred image and a target image, the background loss function isconfigured to indicate a degree of difference between a background imagein the transferred image and a background image in the target image, andthe foreground loss function is configured to indicate a degree ofdifference between a foreground image in the transferred image and aforeground image in the target image.

An embodiment of the invention further proposes a terminal, including:at least one processor; and a memory communicatively connected with theat least one processor; wherein, the memory stores instructionsexecutable by the at least one processor, and when being executed by theat least one processor, the instructions enable the at least oneprocessor to execute the method for generating training data describedabove.

Compared with conventional art, in the embodiments of the presentdisclosure, the image style transfer model is determined by minimizingthe loss function, that is, the more accurate the determined lossfunction is, the closer the transferred image determined by the imagestyle transfer model is to the target image. Generally, an imageincludes the foreground image and the background image, and if the itemsin the foreground image or the background image are in a jumble, aninaccurate loss function is often obtained when determining the lossfunction. In this embodiment, the foreground loss function andbackground loss function are determined respectively, and the lossfunction is determined collectively by the foreground loss function, thebackground loss function and the original loss function, thus avoidinginfluence of the foreground image to the background image or influenceof the background image to the foreground image, thereby greatlyimproving accuracy of the determined loss function. Since the differencebetween the target image and the transferred image determined from theimage style transfer model and the original image is small, the accuracyof the training data determined based on the transfer data is improved,and thus the accuracy of the training model obtained with the trainingdata is improved.

Further, the method for generating training data further includesperforming the following step before obtaining the original image:obtaining a first image set and a second image set, wherein first imagesin the first image set have the same image style as that of the originalimage, and second images in the second image set have the same imagestyle as that of the transferred image; determining the original lossfunction, the background loss function and the foreground loss functionrespectively according to the first image set and the second image set;and minimizing the loss function determined by the original lossfunction, the background loss function and the foreground loss function,so as to construct the image style transfer model. Before obtaining theoriginal image, training is performed by using a large number of thefirst images and the second images to determine the original lossfunction, background loss function and foreground loss function, therebyconstructing an accurate image style transfer model.

Furthermore, the step of determining the original loss function, thebackground loss function, and the foreground loss function respectivelyaccording to the first image set and the second image set includes:segmenting each of the first images in the first image set into a firstforeground image and a first background image, and segmenting each ofthe second images in the second image set into a second foreground imageand a second background image; determining the original loss functionaccording to each of the first images and each of the second images;determining the foreground loss function according to each of the firstforeground images and each of the second foreground images; anddetermining the background loss function according to each of the firstbackground images and each of the second background images. Bysegmenting each of the first images and each of the second images, theforeground loss function and the background loss function may bedetermined quickly and accurately.

Further, after obtaining the original image and before determining thetransferred image, the method for generating training data furtherincludes: converting the original image into an image composed based onhue, saturation, and value, if it is determined that the original imageis not an image composed based on hue, saturation, and value. The imagebased on hue, saturation and value has low sensitivity to colors, andimage transferring is an operation for transferring the image style,which requires to ensure that the colors are unchanged or changedlittle, thus it may greatly improve the accuracy of transferring imagesby converting the original image into an image based on hue, saturation,and value.

Further, the step of determining the foreground loss function accordingto each of the first foreground images and each of the second foregroundimages specifically includes: according to each of the first foregroundimages and each of the second foreground images, calculating a firstexpectation function for converting an image style to which the firstforeground image belongs into an image style to which the secondforeground image belongs, and calculating a second expectation functionfor converting the image style to which the second foreground imagebelongs into the image style to which the first foreground imagebelongs; and taking a sum of the first expectation function and thesecond expectation function as the foreground loss function. Theforeground loss function is determined according to the firstexpectation function and the second expectation function, such that aflexible conversion between the image style to which the firstforeground image belongs and the image style to which the secondforeground image belongs is achieved by the foreground loss function.

Further, the step of determining the background loss function accordingto each of the first background images and each of the second backgroundimages includes: according to each of the first background images andeach of the second background images, calculating a third expectationfunction for converting an image style to which the first backgroundimage belongs into an image style to which the second background imagebelongs, and calculating a fourth expectation function for convertingthe image style to which the second background image belongs into theimage style to which the first background image belongs; and taking asum of the third expectation function and the fourth expectationfunction as the background loss function. The background loss functionis determined according to the third expectation function and the fourthexpectation function, such that a flexible conversion between the imagestyle to which the first background image belongs and the image style towhich the second background image belongs is achieved by the backgroundloss function.

Furthermore, the step of determining the training data according to thetransferred image specifically includes: converting the transferredimage based on hue, saturation, and value back to an image based onthree primary colors; and taking the transferred image obtained afterthe conversion as the training data. This ensures the stability ofcolors in the transferred image.

BRIEF DESCRIPTION

Some of the embodiments will be described in detail, with references tothe following Figures, wherein like designations denote like members,wherein:

FIG. 1 is a schematic flowchart of a method for generating training dataaccording to a first embodiment of the present disclosure;

FIG. 2 is a schematic flowchart for constructing an image style transfermodel according to the first embodiment of the present disclosure;

FIG. 3 is a schematic flowchart of a method for generating training dataaccording to a second embodiment of the present disclosure;

FIG. 4 is a schematic diagram illustrating a specific structure of adevice for generating training data according to a third embodiment ofthe present disclosure; and

FIG. 5 is a schematic diagram illustrating a specific structure of aterminal according to a fourth embodiment of the present disclosure.

DETAILED DESCRIPTION

In order to make the objectives, technical solutions, and advantages ofthe embodiments of the present disclosure clearer, the embodiments ofthe present disclosure will be explained in detail with reference to theaccompanying drawings. However, a person of ordinary skill in the artcould understand that, in various embodiments of the present disclosure,many technical details are provided for the reader to better understandthe present application. However, the technical solution claimed in thisapplication can be implemented without these technical details andvarious changes and modifications based on the following embodiments.

A first embodiment of the present disclosure relates to a method forgenerating training data. The method for generating training data isapplied to a terminal having a calculation function. The generatedtraining data may be used for training an object identification model.For example, a large amount of training data comprising a container andgoods in the container is used to train a goods identification model.The specific flow of the method for generating the training data isshown in FIG. 1.

Step 101: Obtaining an original image

Specifically, the original image may be obtained through an input. Theoriginal image may be a composite image. The composite image may beobtained through a 3D model that completely simulates a real object. Forexample, by simulating a 3D image for the container and a 3D image forthe goods in the container, combining the simulated 3D images and thenrendering the combined image by a virtual camera, a composite image forthe container placed with the goods is obtained; or by simulating a 3Dimage for the goods in the container, combining the simulated 3D imagewith a real 2D background image and re-rendering the combined image by avirtual camera, the composite image may also be obtained. Since thecomposite image does not need to be manually collected, composite imagesof different styles may be generated by adjusting an angle forsimulating the 3D images for the goods, distortion degree of the cameraand illumination intensity within the container, so as to meetrequirements for training the goods identification model.

It shall be understood that the original image may also be a real image,for example, images of the container and the goods in the containertaken in a real environment.

Step 102: Determining a transferred image according to an image styletransfer model and the original image. The image style transfer model isobtained by minimizing a loss function, and the loss function isdetermined according to an original loss function, a background lossfunction, and a foreground loss function.

Specifically, the image style transfer model is configured to convertimages of different image styles. For example, the image style transfermodel may convert an image of oil painting style into an image of cameraimage style, or convert an image of camera image style into an image ofoil painting style. The image style transfer model is obtained byminimizing the loss function, and the loss function is determinedaccording to the original loss function, the background loss functionand the foreground loss function. The original loss function isconfigured to indicate the degree of difference between the transferredimage and a target image. The background loss function is configured toindicate the degree of difference between the background image in thetransferred image and the background image in the target image. Theforeground loss function is configured to indicate the degree ofdifference between the foreground image in the transferred image and theforeground image in the target image.

Specifically, it may be understood that the target image may be a realimage having the same image style as that of the transferred image; andthe transferred image is determined according to the image styletransfer model. That is to say, the transferred image may be understoodas a predicted image determined based on the image style transfer modeland the original image, and the target image may be understood as a realimage. Therefore, the original loss function may be configured toindicate the degree of difference between the predicted image and thereal image in its entirety. An image includes a foreground image and abackground image, taking an image captured within the container as anexample, the foreground image is an image for goods in the container,and the background image is an image for the container. Similarly, thebackground loss function may indicate the degree of difference between apredicted image representing the background and the real backgroundimage, and the foreground loss function may indicate the degree ofdifference between a predicted image representing the foreground and thereal foreground image.

Each time an original image is obtained, a transferred image of anotherimage style may be determined according to the image style transfermodel.

Step 103: Determining training data according to the transferred image.

Specifically, the transferred image may be directly used as trainingdata.

It should be understood that before obtaining the original image in step101, the image style transfer model needs to be constructed, and theimage style transfer model may be constructed by using the sub-stepsshown in FIG. 2.

Step 1011: Obtaining a first image set and a second image set. The firstimages in the first image set have the same image style as that of theoriginal image, and the second images in the second image set have thesame image style as that of the transferred image.

Specifically, the first image set needs to include a large number offirst images, and the second image set needs to include a large numberof second images. It is only necessary to ensure that the image style ofeach of the first images is different from the image style of each ofthe second images. The first images and the second images do not have tohave a one-to-one correspondence therebetween, that is, the first imagesin the first image set do not have to be paired with the second imagesin the second image set. For example, the first image is an image for anorange of a color oil painting style, and the second image may be animage for a pear captured by a camera.

It should be noted that in the process of constructing the image styletransfer model, each of the first images in the first image set may bean image based on hue, saturation, and value, thereby reducing the colorsensitivity in the model construction process and improving accuracy ofthe constructed model.

Step 1012: Determining the original loss function, the background lossfunction, and the foreground loss function respectively according to thefirst image set and the second image set.

In a specific implementation, each of the first images in the firstimage set is segmented into a first foreground image and a firstbackground image, and each of the second images in the second image setis segmented into a second foreground image and a second backgroundimage; the original loss function is determined according to each of thefirst images and each of the second images; the foreground loss functionis determined according to each of the first foreground images and eachof the second foreground images; the background loss function isdetermined according to each of the first background images and each ofthe second background images.

Specifically, in the process of constructing the image style transfermodel, each of the first images and the second image is segmented. Ifthe image is a composite image, it may be segmented directly; if theimage is a real image, firstly, objects belonging to the foreground inthe image is circled with a foreground labelling box, and the imagebelonging to the background is circled with a background labelling box,thus the image may be segmented according to different labelling boxes.Segmentation for the real image may also be performed by using othermethods, which will not be repeated herein.

The image style transfer model is a cyclic generative adversarialnetwork model, the original loss function is determined based on each ofthe first images and each of the second images, that is, the originalloss function is determined based on the complete first images and thecomplete second images. The original loss function for the image styletransfer model is defined as in the following formula (1):

L _(style) =L _(GAN)(G, D _(Y) , X, Y)+L _(GAN)(F, D _(X) , X, Y)+λ₁ L_(cyc)(G, F)   formula(1);

Where, L_(style) represents the original loss function, X represents thefirst image set, Y represents the second image set, G represents theimage style mapping function from X to Y, F represents the image stylemapping function from Y to X, and D_(X) represents a discriminator forthe image style to which the first image belongs, and D_(Y) represents adiscriminator for the image style to which the second image belongs.L_(GAN) represents the standard adversarial loss, L_(cyc) represents thecyclic consistency loss, and λ₁ represents the parameter indicating thetrade-off among the three losses.

In a specific implementation, the process for determining the foregroundloss function may be as follows: according to each of the firstforeground images and each of the second foreground images, calculatinga first expectation function for converting the image style to which thefirst foreground image belongs into the image style to which the secondforeground image belongs, and a second expectation function forconverting an image style to which the second foreground image belongsinto an image style to which the first foreground image belongs; andtaking a sum of the first expectation function and the secondexpectation function as the foreground loss function.

Specifically, the foreground loss function can be expressed by thefollowing formula (2):

$\begin{matrix}{L_{FG} = {{E_{x\sim{{pdata}{(x)}}}\left\lbrack {{\left( {{G(x)}_{H} - x_{H}} \right) \odot {M_{FG}(x)}}}_{2} \right\rbrack} + {E_{y\sim{{pdata}{(y)}}}\left\lbrack {{\left( {{F(y)}_{H} - y_{H}} \right) \odot {M_{FG}(y)}}}_{2} \right\rbrack}}} & {{formula}(2)}\end{matrix}$

In the formula (2), x˜pdata (x) represents a data distribution of X,y˜pdata (y) represents a data distribution of Y, M_(FG)(x) representsthe foreground images of all objects in the first image x, and M_(FG)(y)represents the foreground images of all objects in the second image y,“⊙” is the product of tensors; H represents that the application is onthe Hue channel. That is, the first item in the formula (2) representsthe first expectation function, and the second item represents thesecond expectation function.

In a specific implementation, the process for determining the backgroundloss function may be as follows: according to each of the firstbackground images and each of the second background images, calculatinga third expectation function for converting the image style to which thefirst background image belongs into the image style to which the secondbackground image belongs, and a fourth expectation function forconverting the image style to which the second background image belongsinto the image style to which the first background image belongs; andtaking the sum of the third expectation function and the fourthexpectation function as the background loss function.

Specifically, the background loss function may be expressed by thefollowing formula (3):

$\begin{matrix}{L_{BG} = {{E_{x\sim{{pdata}{(x)}}}\left\lbrack {{\left( {{G(x)}_{H} - x_{H}} \right) \odot {M_{BG}(x)}}}_{2} \right\rbrack} + {E_{y\sim{{pdata}{(y)}}}\left\lbrack {{\left( {{F(y)}_{H} - y_{H}} \right) \odot {M_{BG}(y)}}}_{2} \right\rbrack}}} & {{formula}(3)}\end{matrix}$

In the formula (3), x˜pdata (x) represents the data distribution of X ,y˜pdata (y) represents the data distribution of Y, M_(BG)(x) representsthe background image of all objects in the first image x, and M_(BG)(y)represents the background image of all objects in the second image y,“⊙” represents the product of tensors, where H represents theapplication on the Hue channel; that is, the first item in the formula(3) represents the third expectation function, and the second itemrepresents the fourth expectation function.

Step 1013: Minimizing the loss function determined by the original lossfunction, the background loss function and the foreground loss function,and constructing the image style transfer model.

Specifically, the image style transfer model is determined by theoriginal loss function, the background loss function and the foregroundloss function (that is, it can be determined according to formula (1),formula (2) and formula (3)), then the loss function may be representedby the following formula (4):

L _(OD) =L _(style)+λ₂ L _(FG)+λ₃ L _(BG)   formula (4)

Where, L_(OD) represents the loss function of the image style transfermodel, and λ2 and λ3 represent the trade-off parameters indicatingtrade-off among the loss functions. It can be understood that thespecific values of λ₁, λ₂, and λ3 may be set according to actualtraining. For example, λ₁, λ₂, and λ₃ may be set to 10, 3, and 7,respectively.

It is worth mentioning that, when adopting a cyclic generativeadversarial network model, the image information of the model can be setaccording to the practical application. For example, the imageresolution in the image style transfer model may be set to 1000*1000. Inaddition, after the image style is transferred, the transfer-mage shouldcontain key information in the original image, such as colorinformation, contour information of each item in the original image, andso on.

Compared with conventional art, in the embodiments of the presentdisclosure, the image style transfer model is determined by minimizingthe loss function, that is, the more accurate the determined lossfunction is, the closer the transferred image determined by the imagestyle transfer model is to the target image. Generally, an imageincludes the foreground image and the background image, and if the itemsin the foreground image or the background image are in a jumble, aninaccurate loss function is often obtained when determining the lossfunction. In this embodiment, the foreground loss function andbackground loss function are determined respectively, and the lossfunction is determined collectively by the foreground loss function, thebackground loss function and the original loss function, thus avoidinginfluence of the foreground image to the background image or influenceof the background image to the foreground image, thereby greatlyimproving accuracy of the determined loss function. Since the differencebetween the target image and the transferred image determined from theimage style transfer model and the original image is small, the accuracyof the training data determined based on the transfer data is improved,and thus the accuracy of the training model obtained with the trainingdata is improved.

A second embodiment of the present disclosure relates to a method forgenerating training data. The second embodiment relates to a furtherimprovement to the first embodiment, the main improvement lies in thatin the second embodiment of the present disclosure, after obtaining theoriginal image and before determining the transferred image, aconversion is performed on the original image if it is determined thatthe original image is not composed based on hue, saturation, and value.The specific flow of the method for generating the training data isshown in FIG. 3.

Step 201: Obtaining an original image.

Step 202: If it is determined that the original image is not an imagecomposed based on hue, saturation, and value, converting the originalimage into an image based on hue, saturation, and value.

Specifically, an image composed based on hue, saturation, and value isan image in the color space of hue, saturation, and value (or “HSV”);and an image based on three primary colors is generally an image in theRGB color space. Since the images based on the RGB color space are verysensitive to color changes, in order to determine that the transferredimage determined according to the original image can retain the colorsin the original image, it is necessary to first determine whether theoriginal image is in the HSV color space. If it is not in the HSV colorspace, the original image is converted into an image based on the HSVcolor space. It is needless to say that if the original image is basedon the HSV color space, there is no need to convert the color space ofthe original image.

In other words, the original image is not limited by the color space.When the original image is not in the HSV color space, upon convertingthe color space, transfer of image style is possible.

Step 203: Determining the transferred image according to the image styletransfer model and the original image. The image style transfer model isobtained by minimizing a loss function, and the loss function isdetermined according to the original loss function, the background lossfunction and the foreground loss function.

Step 204: Determining training data according to the transferred image.

Specifically, if it is determined that the original image is not animage composed based on hue, saturation, and value, then, upondetermining the transferred image, the transferred image needs to beconverted back to an image based on the three primary colors, that is,the transferred image is converted from the HSV color space back intoRGB color space, and this transferred image obtained after theconversion is taken as the final training data.

It should be noted that steps 201, 203, and 204 in this embodiment aresubstantially the same as steps 101, 102, and 103 in the firstembodiment, and details are not described herein again.

According to the method for generating training data in this embodiment,through determining the color space to which the original image belongs,even if the original image is not an image based on the HSV color space,the transfer of image style is implementable by converting the originalimage into an image based on HSV color space, thus enhancing flexibilityof obtaining the training data.

The steps shown in the above method are merely for clarity ofdescription, and while implemented they can be combined into one step orsome steps may be divided by segmenting into multiple steps, all ofwhich are within the scope of protection of embodiments of theinvention, as long as the variant includes the same logicalrelationship. Any modification where insignificant amendments are addedto the algorithms or flows or insignificant designs are introduced intothe algorithms or flows, without changing the core designs of thealgorithms and flows, is within the scope of protection of embodimentsof the invention.

The third embodiment of the present disclosure relates to a device forgenerating training data. The device 30 for generating training dataincludes: an obtaining module 301, a first determining module 302, and asecond determining module 303. The specific structure of the device forgenerating training data is shown in FIG. 4.

The obtaining module 301 is configured to obtain the original image; thefirst determining module 302 is configured to determine the transferredimage according to a image style transfer model and the original image,where the image style transfer model is obtained by minimizing to lossfunction, and the loss function is determined based on an original lossfunction and a background loss function and a foreground loss function;the second determining module 303 is configured to determine thetraining data according to the transferred image; wherein the originalloss function is configured to indicate the degree of difference betweenthe transferred image and the target image, and the background lossfunction is configured to indicate the degree of difference between thebackground image in the transferred image and the background image inthe target image, and the foreground loss function is configured toindicate the degree of difference between the foreground image in thetransferred image and the foreground image in the target image.

It is readily found that this embodiment is a device embodimentcorresponding to the first embodiment, and it can be implemented incooperation with the first embodiment. The related technical detailsmentioned in the first embodiment are still valid in this embodiment,and will not be repeated for reduction of duplication. Accordingly, therelated technical details mentioned in this embodiment may also beapplied in the first embodiment.

It is worth mentioning that each module involved in this embodiment is alogic module. In practical applications, a logical unit may be aphysical unit, or a part of a physical unit, and may also be implementedas a combination of multiple physical units. In addition, in order tohighlight the innovative part of the present disclosure, units that arenot closely related to solving the technical problem proposed by thepresent disclosure are not introduced in this embodiment, but this doesnot mean that there are no other units in this embodiment.

The fourth embodiment of the present disclosure relates to a terminal.The specific structure of the terminal 40 is shown in FIG. 5, including:at least one processor 401; and a memory 402 communicatively connectedto the at least one processor; wherein the memory is stored withinstructions thereon and the instructions may be executed by at leastone processor, and when being executed by at least one processor, theinstructions enable the at least one processor to perform the method forgenerating training data in the first embodiment or the secondembodiment.

The memory 402 and the processor 401 are connected with a bus. The busmay include any number of interconnected buses and bridges. The busconnects various circuits of one or more processors 401 and the memory402 together. The bus may also connect various other circuits such asperipherals, voltage regulators, and power management circuits together,which are well known in the art, so the description thereof are omittedherein. The bus interface provides an interface between the bus and atransceiver. The transceiver may be a single component or multiplecomponents, such as multiple receivers and transmitters, which providesa unit for communicating with various other devices over a transmissionmedium. The data processed by the processor 401 is transmitted on awireless medium through an antenna. Further, the antenna also receivesdata and transmits the data to the processor 401.

The processor 401 is responsible for managing the bus and generalprocessing, and can also provide various functions, including timing,peripheral interfaces, voltage regulation, power management, and othercontrol functions. The memory 402 may be configured to store data usedby the processor 401 when performing operations.

Those skilled in the art can understand that all or part of the steps inthe method of the above embodiments may be implemented by a programinstructing related hardware. The program is stored in a storage mediumand includes several instructions to enable a device (which can be asingle-chip computer, Chip, etc.) or a processor to execute all or partof the steps of the method described in each embodiment of the presentapplication. The foregoing storage medium includes: U disks, mobile harddisks, Read-Only Memory (ROM), Random Access Memory (RAM), magneticdisks, or optical disks and other media that can store program codes.

A person of ordinary skill in the art can understand that the foregoingembodiments are specific embodiments for implementing the presentdisclosure, and in practical applications, various changes can be madein form and details without departing from the spirit and scope ofembodiments of the invention.

What is claimed is:
 1. A method for generating training data,comprising: obtaining an original image; determining a transferred imageaccording to an image style transfer model and the original image,wherein the image style transfer model is obtained by minimizing a lossfunction, and the loss function is determined according to an originalloss function, a background loss function, and a foreground lossfunction; and determining the training data according to the transferredimage; wherein, the original loss function is configured to indicate adegree of difference between the transferred image and a target image,and the background loss function is configured to indicate a degree ofdifference between a background image in the transferred image and abackground image in the target image, the foreground loss function isconfigured to indicate a degree of difference between a foreground imagein the transferred image and a foreground image in the target image. 2.The method for generating training data according to claim 1, furthercomprising performing the following steps before obtaining the originalimage: obtaining a first image set and a second image set, wherein firstimages in the first image set have a same image style as that of theoriginal image, and second images in the second image set have a sameimage style as that of the transferred image; determining the originalloss function, the background loss function and the foreground lossfunction respectively according to the first image set and the secondimage set; and minimizing the loss function determined by the originalloss function, the background loss function and the foreground lossfunction, so as to construct the image style transfer model.
 3. Themethod for generating training data according to claim 2,wherein thedetermining the original loss function, the background loss function andthe foreground loss function respectively according to the first imageset and the second image set comprises: segmenting each of the firstimages in the first image set into a first foreground image and a firstbackground image, and segmenting each of the second images in the secondimage set into a second foreground image and a second background image;determining the original loss function according to each of the firstimages and each of the second images; determining the foreground lossfunction according to each of the first foreground images and each ofthe second foreground images; and determining the background lossfunction according to each of the first background images and each ofthe second background images.
 4. The method for generating training dataaccording to claim 3, further comprising performing the following stepafter obtaining the original image and before determining thetransferred image: converting the original image into an image composedbased on hue, saturation, and value, if it is determined that theoriginal image is not an image composed based on hue, saturation, andvalue.
 5. The method for generating training data according to claim 3,wherein, the determining the foreground loss function according to eachof the first foreground images and each of the second foreground imagescomprises: according to each of the first foreground images and each ofthe second foreground images, calculating a first expectation functionfor converting an image style to which the first foreground imagebelongs into an image style to which the second foreground imagebelongs, and calculating a second expectation function for convertingthe image style to which the second foreground image belongs into theimage style to which the first foreground image belongs; and taking asum of the first expectation function and the second expectationfunction as the foreground loss function.
 6. The method for generatingtraining data according to claim 3, wherein, the determining thebackground loss function according to each of the first backgroundimages and each of the second background images comprises: according toeach of the first background images and each of the second backgroundimages, calculating a third expectation function for converting an imagestyle to which the first background image belongs into an image style towhich the second background image belongs, and calculating a fourthexpectation function for converting the image style to which the secondbackground image belongs into the image style to which the firstbackground image belongs; and taking a sum of the third expectationfunction and the fourth expectation function as the background lossfunction.
 7. The method for generating training data according to claim4, wherein, the determining the training data according to thetransferred image comprises: converting the transferred image based onhue, saturation, and value back to an image based on three primarycolors; and taking the transferred image obtained after the conversionas the training data.
 8. The method for generating training dataaccording to claim 5, wherein, the image style transfer model is acyclic generative adversarial network model.
 9. The method forgenerating training data according to claim 6, wherein, the image styletransfer model is a cyclic generative adversarial network model.
 10. Adevice for generating training data, comprising: an obtaining module, afirst determining module, and a second determining module; wherein: theobtaining module is configured to obtain an original image; the firstdetermining module is configured to determine a transferred imageaccording to an image style transfer model and the original image, theimage style transfer model is obtained by minimizing a loss function,and the loss function is determined according to an original lossfunction, a background loss function, and a foreground loss function;the second determining module is configured to determine the trainingdata according to the transferred image; wherein, the original lossfunction is configured to indicate a degree of difference between thetransferred image and a target image, the background loss function isconfigured to indicate a degree of difference between a background imagein the transferred image and a background image in the target image, andthe foreground loss function is configured to indicate a degree ofdifference between a foreground image in the transferred image and aforeground image in the target image.
 11. A terminal for generatingtraining data, comprising: at least one processor; and a memorycommunicatively connected with the at least one processor; wherein, thememory stores instructions executable by the at least one processor, andwhen being executed by the at least one processor, the instructionsenable the at least one processor to implement a method comprising:obtaining an original image; determining a transferred image accordingto an image style transfer model and the original image, wherein, theimage style transfer model is obtained by minimizing a loss function,and the loss function is determined according to an original lossfunction, a background loss function and a foreground loss function; anddetermining the training data according to the transferred image;wherein, the original loss function is configured to indicate a degreeof difference between the transferred image and a target image, and thebackground loss function is configured to indicate a degree ofdifference between a background image in the transferred image and abackground image in the target image, the foreground loss function isconfigured to indicate a degree of difference between a foreground imagein the transferred image and a foreground image in the target image. 12.The terminal according to claim 11, wherein, the instructions enable theat least one processor to further implement the following steps beforeobtaining the original image: obtaining a first image set and a secondimage set, wherein first images in the first image set have a same imagestyle as that of the original image, and second images in the secondimage set have a same image style as the transferred image; determiningthe original loss function, the background loss function and theforeground loss function respectively according to the first image setand the second image set; and minimizing the loss function determined bythe original loss function, the background loss function and theforeground loss function, so as to construct the image style transfermodel.
 13. The terminal according to claim 12, wherein, the determiningthe original loss function, the background loss function and theforeground loss function respectively according to the first image setand the second image set comprises: segmenting each of the first imagesin the first image set into a first foreground image and a firstbackground image, and segmenting each of the second images in the secondimage set into a second foreground image and a second background image;determining the original loss function according to each of the firstimages and each of the second images; determining the foreground lossfunction according to each of the first foreground images and each ofthe second foreground images; and determining the background lossfunction according to each of the first background images and each ofthe second background images.
 14. The terminal according to claim 13,wherein, the instructions enable the at least one processor to furtherimplement the following step after obtaining the original image andbefore determining the transferred image: converting the original imageinto an image composed based on hue, saturation, and value, if it isdetermined that the original image is not an image composed based onhue, saturation, and value.
 15. The terminal according to claim 13,wherein, the determining the foreground loss function according to eachof the first foreground images and each of the second foreground imagescomprises: according to each of the first foreground images and each ofthe second foreground images, calculating a first expectation functionfor converting an image style to which the first foreground imagebelongs into an image style to which the second foreground imagebelongs, and calculating a second expectation function for convertingthe image style to which the second foreground image belongs into theimage style to which the first foreground image belongs; and taking asum of the first expectation function and the second expectationfunction as the foreground loss function.
 16. The terminal according toclaim 13, wherein, the determining the background loss functionaccording to each of the first background images and each of the secondbackground images comprises: according to each of the first backgroundimages and each of the second background images, calculating a thirdexpectation function for converting an image style to which the firstbackground image belongs into an image style to which the secondbackground image belongs, and calculating a fourth expectation functionfor converting the image style to which the second background imagebelongs into the image style to which the first background imagebelongs; and taking a sum of the third expectation function and thefourth expectation function as the background loss function.
 17. Theterminal according to claim 14, wherein, the determining the trainingdata according to the transferred image comprises: converting thetransferred image based on hue, saturation, and value back to an imagebased on three primary colors; taking the transferred image obtainedafter the conversion as the training data.
 18. The terminal according toclaim 15, wherein, the image style transfer model is a cyclic generativeadversarial network model.
 19. The terminal according to claim 16,wherein, the image style transfer model is a cyclic generativeadversarial network model
 20. A computer readable medium having storedthereon a computer program, when being executed by a processor, theprogram implementing the method for generating training data accordingto claim 1.